<?php
/**
 * 业务招待费
 * Created by PhpStorm.
 * User: 23783
 * Date: 2018/3/15
 * Time: 10:01
 */
namespace Controllers\Pdf;
use Common\CommonMethod;

class BusinessEntertainingPdf{
    protected $pdf;
    protected $common;

    public function __construct()
    {
        global $tcPdf;
        $this->pdf  = $tcPdf;
        $this->common= new CommonMethod();
    }

    /**
     * 业务招待费报销单
     * @param $result
     */
    function CreatePdfDocument($result){
        $this->pdf->AddPage();
        // 设置文档信息
        $this->pdf->SetCreator('Lane');
        $this->pdf->SetAuthor('Lane');
        $this->pdf->SetTitle('业务招待费报销单');
        //删除预定义的打印 页眉/页尾
        $this->pdf->setPrintHeader(false);
        $this->pdf->setPrintFooter(false);
        //设置字体 - 正文标题的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', 'B', 15);
        $this->pdf->Write(20, '业务招待费报销单', '', 0, 'C', true, 0, false, false, 0);
        //设置字体 - 正文内容的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', '', 10);
        //设置页面边幅：
        $this->pdf->Cell(140, 12, '业务招待费报销单', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '招待类型:', 1, 0, 'R');
        $this->pdf->Cell(25, 6,$this->common->PropertyEnumIdByName($result['paras']['RIBUTION']), 1, 1, 'C');
        $this->pdf->Cell(140, 6, '', 0, 0, 'C');
        $this->pdf->Cell(25, 6, '费用类别:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['paras']['TYPE'], 1, 1, 'C');
        //第二行
        $this->pdf->Cell(25, 6, '所属部门:', 1, 0, 'R');
        $this->pdf->Cell(45, 6, $result['UF_DEPARTMENT'], 1, 0, 'C');
        $this->pdf->Cell(20, 6, '申请人姓名', 1, 0, 'R');
        $this->pdf->Cell(50, 6, $result['USER_NAME'], 1, 0, 'C');
        $this->pdf->Cell(25, 6, '联系电话:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['PERSONAL_MOBILE'], 1, 1, 'C');
        //第三行
        $this->pdf->Cell(25, 6, '项目/预算编号:', 1, 0, 'R');
        $this->pdf->Cell(45, 6, $result['paras']['PROJECT'], 1, 0, 'C');
        $this->pdf->Cell(20, 6, '预算名称:', 1, 0, 'R');
        $this->pdf->Cell(50, 6, $result['paras']['BUDGETNAME'], 1, 0, 'C');
        $this->pdf->Cell(25, 6, '是否在预算内:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $this->common->PropertyEnumIdByName($result['paras']['BUDGET']), 1, 1, 'C');
        //第四行
        $this->pdf->Cell(25, 6, ' 转账账户:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['paras']['BANKNUMBER'], 1, 0, 'C');
        $this->pdf->Cell(20, 6, '账户抬头: ', 1, 0, 'R');
        $this->pdf->Cell(70, 6, $result['paras']['HEADER'], 1, 0, 'C');
        $this->pdf->Cell(25, 6, '接收方式:', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $this->common->PropertyEnumIdByName($result['paras']['METHOD']), 1, 1, 'C');

        $this->pdf->Cell(50, 6, '招待说明', 1, 0, 'C');
        $this->pdf->Cell(20, 6, '招待形式', 1, 0, 'C');
        $this->pdf->Cell(20, 6, '招待人数', 1, 0, 'C');
        $this->pdf->Cell(35, 6, '姓名', 1, 0, 'C');
        $this->pdf->Cell(15, 6, '单位', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '费用标准', 1, 0, 'C');
        $this->pdf->Cell(25, 6, '总金额', 1, 1, 'C');


        $this->pdf->MultiCell(50, 28,  $result['paras']['EAT_NAME'], 1, 'L',false,0, '', '', true, 0,false,true,0, 'M', true);
        $this->pdf->Cell(20, 14, '餐费', 1, 0, 'C');
        $this->pdf->Cell(20, 14, $result['paras']['EAT_NUM'], 1, 0, 'C');

        $this->pdf->MultiCell(35, 14,  $result['paras']['EAT_NAME'], 1, 'L',false,0, '', '', true, 0,false,true,0, 'M', true);
        $this->pdf->Cell(15, 14, $result['paras']['EAT_COMPANY'], 1, 0, 'C');
        $this->pdf->Cell(25, 14, $result['paras']['EAT_STANDARD'].'/'.'人', 1, 0, 'C');
        $this->pdf->Cell(25, 14, $result['paras']['EAT_TOTAL'].'元', 1, 1, 'C');

        $this->pdf->Cell(50, 14, '', 0, 0, 'C');
        $this->pdf->Cell(20, 14, '礼品', 1, 0, 'C');
        $this->pdf->Cell(20, 14, $result['paras']['GIFT_NUM'], 1, 0, 'C');
        $this->pdf->MultiCell(35, 14,$result['paras']['GIFT_NAME'], 1, 'L',false,0, '', '', true, 0,false,true,0, 'M', true);
        $this->pdf->Cell(15, 14, $result['paras']['GIFT_COMPANY'], 1, 0, 'C');
        $this->pdf->Cell(25, 14, $result['paras']['GIFT_STANDARD'].'/'.'人', 1, 0, 'C');
        $this->pdf->Cell(25, 14, $result['paras']['GIFT_TOTAL'].'元', 1, 1, 'C');



        $this->pdf->Cell(35, 6, '合计费用(大写)', 1, 0, 'C');
        $this->pdf->Cell(105, 6, $result['CAPITALMONEY'], 1, 0, 'L');
        $this->pdf->Cell(25, 6, '合计费用(小写)', 1, 0, 'R');
        $this->pdf->Cell(25, 6, $result['paras']['TOTAL'].'元', 1, 1, 'L');

        //审批记录
        $stks_count = count($result['task']);
        $this->pdf->Cell(35, 6*$stks_count, '审批记录：', 1, 0, 'C');
        for ($tasks=0;$tasks<$stks_count;$tasks++){
            if($tasks>0){
                $this->pdf->Cell(35, 6,'' , 0, 0, 'L');
            }
            $this->pdf->Cell(155, 6, $result['task'][$tasks], 0, 1, 'L');
        }

        $this->pdf->Line($this->pdf->GetX()+190, $this->pdf->GetY()-6*$stks_count, $this->pdf->GetX()+190, $this->pdf->GetY(), $style=array('width'=>0.2));
        $this->pdf->Line(45, $y = $this->pdf->GetY(), 200, $y = $this->pdf->GetY(), $style=array('width'=>0.2));
        //输出PDF。第二个参数默认是I，是浏览器预览。D是下载
        $this->pdf->Output('PHP_TO_PDF.pdf', 'I');
    }
}